/**
 * 快速创建组件
 */


export function FormBase(label = '', {ui, widgetConfig = {}} = {}) {
  /**
   * 快速创建base
   * @param label
   * @param ui
   * @param widgetConfig
   * @returns {{ui: {widget: string, label: string, widgetConfig: {type: string}}, type: string}}
   * @constructor
   */
  return {
    type: 'string',
    ui: {
      label,
      widgetConfig: {
        ...widgetConfig
      },
      ...ui
    },
  }
}

export function FormInput(label = '', {ui, widgetConfig = {}} = {}) {
  /**
   * 快速创建input
   * @param label
   * @param ui
   * @param widgetConfig
   * @returns {{ui: {widget: string, label: string, widgetConfig: {type: string}}, type: string}}
   * @constructor
   */
  return {
    type: 'string',
    ui: {widget: 'CusInput',
      label,
      widgetConfig: {
        ...widgetConfig
      },
      ...ui
    },
  }
}

export function FormTextarea(...args) {
  /**
   * 创建textarea
   * @param args
   * @returns {{ui: {widget: string, label: string, widgetConfig: {type: string}}, type: string}}
   * @constructor
   */
  let ret = FormInput(...args)
  ret.ui.widgetConfig.type = 'textarea'
  return ret
}




export function FormInputNativeNumber(label = '', {ui, widgetConfig = {}} = {}) {
  /**
   * 快速创建input number
   * @param label
   * @param ui
   * @param widgetConfig
   * @returns {{ui: {widget: string, label: string, widgetConfig: {type: string}}, type: string}}
   * @constructor
   */
  return {
    type: 'number',
    ui: {widget: 'CusInput',
      label,
      widgetConfig: {
        type: 'number',
        ...widgetConfig
      },
      ...ui
    },
  }
}


export function FormInputNativeInteger(...args) {
  /**
   * 创建integer
   * @param args
   * @returns {{ui: {widget: string, label: string, widgetConfig: {type: string}}, type: string}}
   * @constructor
   */
  let ret = FormInputNativeNumber(...args)
  ret.ui.widgetConfig.subType = 'integer'
  return ret
}


export function FormSelect(label = '', opt = {}) {
  /**
   * 创建select
   * @param label
   * @param opt
   * @returns {{ui: {widget: string, label: string, widgetConfig: {type: string}}, type: string}}
   * @constructor
   */
  let ret = FormBase(label, opt)
  let options = ZY.lodash.get(opt, 'options', [])
  ret.ui.widget = 'CusSelect'
  ret.ui.widgetConfig.options = options
  return ret
}

export function FormRadio(label = '', opt = {}) {
  /**
   * 创建radio
   * @param label
   * @param opt
   * @returns {{ui: {widget: string, label: string, widgetConfig: {type: string}}, type: string}}
   * @constructor
   */
  let ret = FormBase(label, opt)
  let options = ZY.lodash.get(opt, 'options', [])
  ret.ui.widget = 'CusRadio'
  ret.ui.widgetConfig.options = options
  return ret
}

export function FormCheckbox(label = '', opt = {}) {
  /**
   * 创建checkbox
   * @param label
   * @param opt
   * @returns {{ui: {widget: string, label: string, widgetConfig: {type: string}}, type: string}}
   * @constructor
   */
  let ret = FormBase(label, opt)
  let options = ZY.lodash.get(opt, 'options', [])
  ret.ui.widget = 'CusCheckbox'
  ret.ui.widgetConfig.options = options
  return ret
}

export function FormDatePicker(label = '', opt = {}) {
  /**
   * 快速创建DatePicker
   * @param label
   * @param opt
   * @returns {{ui: (*&{label: string, widgetConfig: {}}), type: string}}
   * @constructor
   */
  return FormBase(label, {
    ui: {
      widget: 'CusDatePicker'
    }
  })
}

export function FormSimpleUploader(label = '', opt = {}) {
  /**
   * 快速创建SimpleUploader
   * @param label
   * @param opt
   * @returns {{ui: (*&{label: string, widgetConfig: {}}), type: string}}
   * @constructor
   */
  let ret = FormBase(label, opt)
  ret.ui.widget = 'CusSimpleUploader'
  return ret
}


export function FormImgUploader(label = '', opt = {}) {
  /**
   * 快速创建ImgUploader
   * @param label
   * @param opt
   * @returns {{ui: (*&{label: string, widgetConfig: {}}), type: string}}
   * @constructor
   */
  let ret = FormBase(label, opt)
  ret.ui.widget = 'CusImgUploader'
  return ret
}

export function FormInputNumber(label = '', opt = {}) {
  /**
   * 快速创建ImgUploader
   * @param label
   * @param opt
   * @returns {{ui: (*&{label: string, widgetConfig: {}}), type: string}}
   * @constructor
   */
  const ret = FormBase(label, opt);
  ret.ui.widget = 'CusInputNumber';
  return ret;
}

export function FormColorPicker(label = '', opt = {}) {
  /**
   * 快速创建ImgUploader
   * @param label
   * @param opt
   * @returns {{ui: (*&{label: string, widgetConfig: {}}), type: string}}
   * @constructor
   */
  const ret = FormBase(label, opt);
  ret.ui.widget = 'CusColorPicker';
  return ret;
}
